// pages/mine/mine.js
var app = getApp()
Page({
    data: {
        defaultImg: "",
        defaultName: "点击登陆",
        mineList: [
            {
                imgUrl: './images/001.png',
                text: '我的赛事',
                id: 0
            },
            {
                imgUrl: './images/002.png',
                text: '我的培训',
                id: 1
            },
            {
                imgUrl: './images/003.png',
                text: '我的收藏',
                id: 2
            },
            {
                imgUrl: './images/004.png',
                text: '我的社区',
                id: 3
            },
            {
                imgUrl: './images/006.png',
                text: '我的客服',
                id: 4
            },
            {
                imgUrl: './images/010.png',
                text: '意见反馈',
                id: 5
            } 
        ]
    },
    onListTap (event) {
        let listId = event.currentTarget.dataset.listid
        let memberid = wx.getStorageSync("memberid");
        if (listId === 0) {
            wx.navigateTo({
                url: 'events/events',
            })
        }
        if (listId === 1) {
            wx.navigateTo({
                url: 'train/train',
            })
        }
        if (listId === 2) {
            wx.navigateTo({
                url: 'collect/collect',
            })
        }
        if (listId === 3) {
            wx.navigateTo({
                url: 'bbs/bbs?memberid='+memberid,
            })
        }
        if (listId === 5) {
            wx.navigateTo({
                url: 'opinion/opinion',
            })
        }
    },
    // 用户授权
    onUserInfoTap (event) {
        let userInfo = event.detail.userInfo
        this.setData({
            defaultName: userInfo.nickName,
            defaultImg: userInfo.avatarUrl
        })
    },
    // 加载读取授权信息
    onShow () {
        let that = this
        // 防止异步回调
        app.userInfoReadyCallback = function (res) {
            let userInfo = res.userInfo
            that.setData({
                defaultName: userInfo.nickName,
                defaultImg: userInfo.avatarUrl
            })
        }
        console.log(app)
        if (app.globalData.userInfo) {
            let userInfo = app.globalData.userInfo
            this.setData({
                defaultName: userInfo.nickName,
                defaultImg: userInfo.avatarUrl
            })
        }
        console.log(this.data.defaultImg)
    }
})